package service;

import beans.NewsLabel;
import beans.Page;
import beans.UpdatePage;
import dao.INewsLabelDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class INewsLabelServiceImpl implements INewsLabelService {
    @Autowired
    private INewsLabelDao dao;
    @Override
    public Page<NewsLabel> findCurrentPage(int pagenum,Integer parentId) {
        Page<NewsLabel> page=new Page<>();
        page.setPagenum(pagenum);
        page.setParentId(parentId);
        int totalRow=dao.selectAllCount(parentId);
        page.setTotalRows(totalRow);
        List<NewsLabel> parents=dao.selectParent();
        page.setParents(parents);
        List<NewsLabel> datas=dao.selectCurrentPageNewsLabels(page);
        page.setDatas(datas);

        return page;
    }

    @Override
    public void dele(int deleId) {
        dao.dele(deleId);
    }

    @Override
    public UpdatePage selectById(int id) {
        UpdatePage updatePage=new UpdatePage();

        NewsLabel newsLabel=dao.selectById(id);
        updatePage.setNewsLabel(newsLabel);

        List<NewsLabel> parents=dao.selectParent();
        updatePage.setParents(parents);

        return updatePage;
    }

    @Override
    public void updateById(NewsLabel newsLabel) {
        dao.updateById(newsLabel);
    }

    @Override
    public void add(NewsLabel newsLabel) {
        dao.add(newsLabel);
    }

    @Override
    public List<NewsLabel>  selectByParents() {
        List<NewsLabel> parents= dao.selectParent();
        return parents;
    }

}
